package com.eva.fs.api;

import com.eva.framework.common.api.BaseController;
import com.eva.framework.common.model.ApiResponse;
import com.eva.framework.oss.OSSUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Api(tags = "OSS文件上传")
@RestController
@RequestMapping("/resource/oss/upload")
public class OSSFileUploadController extends BaseController {

    @Resource
    private OSSUtil ossUtil;

    @ApiOperation("上传图片，最大为5M")
    @PostMapping("/image")
    public ApiResponse<OSSUtil.UploadResult> uploadImage(MultipartFile file) {
        return ApiResponse.success(ossUtil.setMaxSize(5).uploadImage(file));
    }

    @ApiOperation("上传文件")
    @PostMapping("/attach")
    public ApiResponse<OSSUtil.UploadResult> uploadFile(MultipartFile file) {
        return ApiResponse.success(ossUtil.upload(file));
    }
}
